﻿using Demo.Filter;
using LightWadf.Processor;
using LightWadf.Result;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web;

namespace Demo.Processor
{
    public class HomeProcessor : AbstractProcessor
    {
        public override void InitRouteRule()
        {
            this.AddRouteRule("/", "Index");
            this.AddRouteRule("/hello", "Hello");
            this.AddRouteRule("/hello/guys", "HelloGuys");
            this.AddRouteRule("/hello/user", "HelloUser");
            this.AddRouteRule("/hello/file", "HelloFile");
            this.AddRouteRule("/pre-{att:t[string],d[test2],l[1,20]}-suf", "TestMeaning");
            this.AddRouteRule("/post", "Post", HttpMethod.Post);
        }

        /// <summary>
        /// / 默认路由示例
        /// 过滤器示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        [TestFilter]
        public string Index(HttpContext context)
        {
            return "index";
        }

        /// <summary>
        /// 参数化路由示例
        /// </summary>
        /// <param name="context"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string TestMeaning(HttpContext context, Dictionary<string, object> param)
        {
            return (string)param["att"];
        }

        /// <summary>
        /// 返回 string 类型示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string Hello(HttpContext context)
        {
            context.Response.Write("test ");
            return "hello";
        }

        /// <summary>
        /// 返回 HtmlResult 类型示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public HtmlResult HelloGuys(HttpContext context)
        {
            return new HtmlResult("View/Home/Hello.html");
        }

        /// <summary>
        /// 返回 FileResult 类型示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public FileResult HelloFile(HttpContext context)
        {
            return new FileResult("View/Home/Hello.html");
        }

        /// <summary>
        /// 返回 RazorResult 类型示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public RazorResult HelloUser(HttpContext context)
        {
            Dictionary<string, object> model = new Dictionary<string, object>();
            model["Name"] = "test";
            return new RazorResult("View/Home/HelloUser.cshtml", model);
        }

        /// <summary>
        /// 返回 JsonResult 类型示例
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JsonResult Post(HttpContext context)
        {
            return new JsonResult("json");
        }

    }
}